#include "reg52.h"

#define SMG_PROT P0

sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

typedef unsigned int u16;
typedef unsigned char u8;

u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
               0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void delay(u16 ten)
{
	while(ten--);
}	

void smg_display(void)
{
  	u8 i = 0;
	for(i=0;i<8;i++)
	{
		switch(i)
		{
			case 0: LSC = 1; LSB = 1; LSA = 1; break;
			case 1: LSC = 1; LSB = 1; LSA = 0; break;
			case 2: LSC = 1; LSB = 0; LSA = 1; break;
			case 3: LSC = 1; LSB = 0; LSA = 0; break;
			case 4: LSC = 0; LSB = 1; LSA = 1; break;
			case 5: LSC = 0; LSB = 1; LSA = 0; break;
			case 6: LSC = 0; LSB = 0; LSA = 1; break;
			case 7: LSC = 0; LSB = 0; LSA = 0; break;
		}
		SMG_PROT=gsmg_code[i];
		delay(50000);
	}
	for(i=0;i<8;i++)
	{
		
	    LSC = 0; LSB = 0; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  delay(25000);
	    LSC = 0; LSB = 0; LSA = 1;
		  SMG_PROT=gsmg_code[i];

			LSC = 0; LSB = 1; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  delay(25000);
	    LSC = 0; LSB = 1; LSA = 1;
		  SMG_PROT=gsmg_code[i];

			LSC = 1; LSB = 0; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  delay(25000);
			LSC = 1; LSB = 0; LSA = 1;
		  SMG_PROT=gsmg_code[i];

			LSC = 1; LSB = 1; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  delay(25000);
			LSC = 1; LSB = 1; LSA = 1;
			SMG_PROT=gsmg_code[i];
	}
	for(i=8;i<16;i++)
	{
		
	    LSC = 0; LSB = 0; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  
	    LSC = 0; LSB = 0; LSA = 1;
		  SMG_PROT=gsmg_code[i];
      delay(25000);
			LSC = 0; LSB = 1; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  
	    LSC = 0; LSB = 1; LSA = 1;
		  SMG_PROT=gsmg_code[i];
      delay(25000);
			LSC = 1; LSB = 0; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  
			LSC = 1; LSB = 0; LSA = 1;
		  SMG_PROT=gsmg_code[i];
      delay(25000);
			LSC = 1; LSB = 1; LSA = 0;
		  SMG_PROT=gsmg_code[i];
		  
			LSC = 1; LSB = 1; LSA = 1;
			SMG_PROT=gsmg_code[i];
			delay(25000);
	}
}
							 
void main()
{
	while(1)
	{
		smg_display();
	}
}